Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Func<...> args have "unnamed" parameters. Is there a way to name them?

Is there a way to named parameters of a generic Func<...> to have support of intellisense?

Example:

Func<int, int, int> f1 = new Func<int, int, int>(
    (a, b) => { return a + b }
);

f1(2, 3);

enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

No. You can define your own delegate/interface, though.

public delegate int DoTheThing(int a, int b);

or

public interface IThingDoer {
    int DoTheThing(int a, int b);
}
over 4 years ago · Santiago Trujillo Report

0

You can't do this with Func<...> since it is already has names for the type parameters (it's just a normal generic type).

You could define a delegate instead (which has to be defined at class level - you can't define it within a method or as a method parameter):

public delegate int MyFunc(int a, int b);

Then you just use it like:

public static int MyMethod(MyFunc myfunc)
{
    return myfunc(1, 2);
}

public static int MyOtherMethod()
{
    return MyMethod((a, b) => a + b);
}

One somewhat grungy workaround could be to use a tuple for the arguments:

public static int MyMethod(Func<(int a, int b), int> myFunc)
{
    return myFunc((1, 2));
}

public static int MyOtherMethod()
{
    return MyMethod(tuple => tuple.a + tuple.b);
}

Then intellisense will tell you the names of the tuple members. I wouldn't do this though - I'm just mentioning it for completeness.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!